	
	<style>
	.help-block {
	    float: left;
	}
	</style>
	<div id="page-content">
			<div class="col-lg-12">
		        <div class="panel">
		            <div class="panel-heading">
		                <h3 class="panel-title" style="text-align: right;">
		                	#@installPJaxGoBackBtn()
		                	添加新用户
		                </h3>
		            </div>
		            <form id="editForm" class="panel-body form-horizontal form-padding">
		            	<div class="form-group">
		                    <label class="col-md-2 control-label">所属单位</label>
		                    <div class="col-md-5">
		                    	<div class="input-group mar-btm">
			                        <input type="hidden" id="orgid" name="sysUser.orgid" class="form-control" value="#if(o)#(o.orgid)#elseif(org)#(org.id)#end">
			                        <input type="hidden" id="userid" name="sysUser.id" class="form-control" value="#(o?o.id:'')">
			                        <input type="text" id="orgname" name="sysUser.orgName" class="form-control" disabled value="#(org?org.name:'')">
			                        <span class="input-group-btn">
			                            <button class="btn btn-primary" type="button" onclick="selectOneOrg()">选择</button>
			                        </span>
		                    	</div>
		                        <small class="help-block">请选择所属单位</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-2 control-label">用户登录名</label>
		                    <div class="col-md-9">
		                        <input type="text"  name="sysUser.username" class="form-control"  value="#(o?o.username:'')">
		                        <small class="help-block">请输入登录名(用来登录系统)</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-2 control-label">密码</label>
		                    <div class="col-md-9">
		                        <input type="password"  name="sysUser.password" class="form-control"  value="" #if(o) placeholder="如果您不想修改密码,请将此项留空!" #end >
		                        <small class="help-block">请输入密码</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-2 control-label">密码确认</label>
		                    <div class="col-md-9">
		                        <input type="password"  name="password2" class="form-control"  value="" #if(o) placeholder="如果您不想修改密码,请将此项留空!" #end>
		                        <small class="help-block">请再次输入密码</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-2 control-label">用户姓名</label>
		                    <div class="col-md-9">
		                        <input type="text"  name="sysUser.name" class="form-control"  value="#(o?o.name:'')">
		                        <small class="help-block">请输入用户姓名</small>
		                    </div>
		                </div>
		                <div class="form-group">
	                    	<label class="col-md-2 control-label">性别</label>
                            <div class="col-md-9">
		                           <input id="sysUserSexMan" class="magic-radio" type="radio" name="sysUser.sex" value="1" #if(o&&o.sex=="1") checked #end>
		                           <label for="sysUserSexMan">男</label>
		                           <input id="sysUserSexWoman" class="magic-radio" type="radio" name="sysUser.sex" value="0" #if(o&&o.sex=="0") checked #end>
		                           <label for="sysUserSexWoman">女</label>
		                    </div>
                        </div>
                        <div class="form-group">
	                    	<label class="col-md-2 control-label">工号</label>
	                        <div class="col-md-9">
		                        <input type="text"  name="sysUser.work_num" class="form-control"  value="#(o?o.work_num:'')">
		                        <small class="help-block">请输入工号</small>
		                    </div>
	                    </div>
	                    <div class="form-group">
		                    <label class="col-md-2 control-label">出生日期</label>
		                    <div class="input-group date form_datetime col-md-4" style="float:left">
			                    <input type="text" id="birth_date" name="sysUser.birth_date" class="form-control"  value="#(o?o.birth_date:'')" readonly>
			                    <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
		                    </div>
	                    </div>
	                    
	                    <div class="form-group">
		                    <label class="col-md-2 control-label">入司日期</label>
				            <div class="input-group date form_datetime col-md-4">
			                    <input type="text" id="startTime" name="sysUser.in_company_date" class="form-control"  value="#(o?o.in_company_date:'')" readonly>
								<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			                </div>
		                </div>
		                <div class="form-group">
			                <label class="col-md-2 control-label">离职时间</label>
				            <div class="input-group date form_datetime col-md-4">
			                    <input type="text" id="dimission_date" name="sysUser.dimission_date" class="form-control"  value="#(o?o.dimission_date:'')" readonly>
								<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			                </div>
		                </div>
                        <div class="form-group">
	                        <label class="col-md-2 control-label">邮箱地址</label>
	                        <div class="col-md-4">
		                        <input type="text"  name="sysUser.email" class="form-control"  value="#(o?o.email:'')">
		                        <small class="help-block">请输入邮箱地址</small>
		                    </div>
	                    	<label class="col-md-1 control-label">移动电话</label>
                            <div class="col-md-4">
		                        <input type="text"  name="sysUser.mobile" class="form-control"  value="#(o?o.mobile:'')">
		                        <small class="help-block">请输入移动电话</small>
		                    </div>
                        </div>
                        <div class="form-group">
	                    	<label class="col-md-2 control-label">身份证号</label>
                            <div class="col-md-4">
		                        <input type="text"  name="sysUser.idcard" class="form-control"  value="#(o?o.idcard:'')">
		                        <small class="help-block">请输入身份证号</small>
		                    </div>
                        </div>
						#if(shiro.hasPermission('sys:user:giveAuth'))
							<div class="form-group">
								<label class="col-md-2 control-label">分配角色</label>
								<div class="col-md-7">
									<div class="input-group mar-btm">
										<input type="text" id="userRoleName" class="form-control" readonly value="#(userRoleName)">
										<input type="hidden" id="userRoleId" name="userRoleId" class="form-control" value="#(userRoleId)">
										<span class="input-group-btn">
											<button class="btn btn-primary" type="button" onclick="selectUserRole()">选择</button>
										</span>
									</div>
								</div>
							</div>
						#end
                        <div class="form-group">
	                    	<label class="col-md-2 control-label">用户职位</label>
	                    	<div class="col-md-9">
		                        <input type="text"  name="sysUser.position" class="form-control"  value="#(o?o.position:'')">
		                        <small class="help-block">请输入用户职位</small>
		                    </div>
	                    </div>
                        <div class="form-group">
	                    	<label class="col-md-2 control-label">用户类型</label>
                            <div class="col-md-9">
		                           <input id="sysUserTypeText" class="magic-radio" type="radio" name="sysUser.type" value="0" #if(o&&o.type=="0") checked #end>
		                           <label for="sysUserTypeText">试用</label>
		                           <input id="sysUserTypeReal" class="magic-radio" type="radio" name="sysUser.type" value="1" #if(o&&o.type=="1") checked #end>
		                           <label for="sysUserTypeReal">正式员工</label>
		                           <input id="sysUserTypeLeave" class="magic-radio" type="radio" name="sysUser.type" value="2" #if(o&&o.type=="2") checked #end>
		                           <label for="sysUserTypeLeave">离职</label>
		                           <input id="sysUserTypeStudy" class="magic-radio" type="radio" name="sysUser.type" value="3" #if(o&&o.type=="3") checked #end>
		                           <label for="sysUserTypeStudy">实习</label>
		                    </div>
                        </div>
                        <div class="form-group">
		                    <label class="col-md-2 control-label">过往经历</label>
		                    <div class="col-md-9">
		                        <textarea rows="8" name="sysUser.experience" class="form-control" #if(view=='detail') readonly #end>#(o?o.experience:'')</textarea>
		                        <small class="help-block">请输入过往经历</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-2 control-label">教育经历</label>
		                    <div class="col-md-9">
		                        <textarea rows="8" name="sysUser.edu_experience" class="form-control" #if(view=='detail') readonly #end>#(o?o.edu_experience:'')</textarea>
		                        <small class="help-block">请输入教育经历</small>
		                    </div>
		                </div>
		                <div class="panel-footer">
		                    <div class="row">
		                        <div class="col-sm-9 col-sm-offset-3">
		                            <button class="btn btn-warning" type="reset">重置</button>
		                            <button class="btn btn-primary" type="submit" >保存</button>
		                        </div>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>
	</div>
	<script>
		var ifEdit = "#(o?'1':'0')";//是否是修改页面
		var validPassword = {};//密码1
		var validPassword2 = {};//密码2
		var validUsername = {};//用户名 唯一性校验
		if(ifEdit=='1'){//如果是修改 , 密码可以为空
			validPassword = {
                stringLength: {
                    max: 15,
                    message: '*密码长度必须小于15'
                }
            };
			validPassword2 = {
                stringLength: {
                    max: 15,
                    message: '*确认密码长度必须小于15'
                },
                identical: {
                	field: 'sysUser.password',
                	message: '*两次输入密码不一致'
                }
            };
			validUsername = {
                notEmpty: {
                    message: '*登录名不能为空'
                },
                stringLength: {
                    max: 15,
                    message: '*登录名长度必须小于15'
                },
                regexp: {
                	regexp: /^[a-zA-Z0-9_]+$/,
                    message: '用户名只能包含大写、小写、数字和下划线'
                }
            }
		}else{//新增的
				validPassword = {
	                notEmpty: {
	                    message: '*密码不能为空'
	                },
	                stringLength: {
	                    max: 15,
	                    message: '*密码长度必须小于15'
	                }
	            }
				
				validPassword2 = {
	                notEmpty: {
	                    message: '密码不能为空'
	                },
	                stringLength: {
	                    max: 15,
	                    message: '*确认密码长度必须小于15'
	                },
	                identical: {
	                	field: 'sysUser.password',
	                	message: '*两次输入密码不一致'
	                }
	            }
				validUsername = {
	                notEmpty: {
	                    message: '*用户名不能为空'
	                },
	                stringLength: {
	                    max: 15,
	                    message: '*用户名长度必须小于15'
	                },
	                remote: {
	                    message: '*用户名已被注册',
	                    url:ctx+'/admin/sys/user/validUsername',
	                    delay:1000
	                },
	                regexp: {
	                	regexp: /^[a-zA-Z0-9_]+$/,
	                    message: '用户名只能包含英文大写/小写、数字和下划线'
	                }
		        }
		}
		function selectOneOrg(){
			//调用选择一个单位组件
			pointLion.selectOneOrg(function(orgNode){
				var type = orgNode.type;
//				if(type=="1"){
//					pointLion.alertMsg("人员不允许直接添加到【子公司】下，只允许添加到【部门】下，请选择相应【部门】!" , "danger" , "small");
//				}else{
					var thisId = $("#orgId").val();//主键
					$("#orgname").val(orgNode.name);//所选单位名称
					$("#orgid").val(orgNode.id);//所选单位id
					resetVali();
//				}
			},null,null,null,null);
		}
		function save(){
			var data = common_ajax.ajaxFunc("/admin/sys/user/save", $('#editForm').serialize(), "json", null);
			if(data.success){
				pointLion.alertMsg("保存成功!" , "success" , "small" , function(){
					location.href = ctx+'/admin/sys/user/getListPage';//跳转到列表页
				});
			}
		}
		//选择用户角色
		function selectUserRole(){
			var userid = $("#userid").val();
			var index = layer.open({
							  type: 2,
							  title: false, //不显示标题栏
							  area: ['370px', '650px'],
							  shade: 0.2,
							  id: 'giveUserRole', //设定一个id，防止重复弹出
							  resize: false,
							  closeBtn: false,
							  isOutAnim : false , 
							  btn: ['确定', '取消'], 
							  btnAlign: 'c',
							  content: ctx+'/admin/sys/user/getGiveUserRolePage?userid='+userid,
							  success: function(layero){
								  giveUserRoleIframe = window[layero.find('iframe')[0]['name']]; 
							  },
							  yes: function(){
								  	var nodes = giveUserRoleIframe.getCheckedNodes();
								  	var nodestr = [];
								  	var nodeNameStr = [];
								  	$.each(nodes,function(i,o){
								  		nodestr.push(o.id);
								  		nodeNameStr.push(o.name);
								  	})
								  	var data = nodestr.join(",");//用户缩勾选的角色
								  	var nameStr = nodeNameStr.join(",");//用户名字
								  	$("#userRoleId").val(data);
								  	$("#userRoleName").val(nameStr);
								  	layer.closeAll();
							  }
						});
	
		}
		function resetVali(){
			if(!$("#editForm").data('bootstrapValidator').isValid()) {  
		        $("#editForm").data('bootstrapValidator').resetForm();  
		    }
		}
		$(document).ready(function() {
			$('.form_datetime').datepicker({format: 'yyyy-mm-dd',weekStart: 1,todayBtn:  1,autoclose: 1,language:  'zh-CN',todayHighlight: 1,forceParse: 0}).on('changeDate',function(){
				resetVali();
			});
		    $('#editForm').bootstrapValidator({
		    		excluded:[":hidden"],//关键配置，表示只对于隐藏域不进行验证，其他的表单元素都要验证
		            fields: {
		            	"sysUser.orgName":{
		            		validators: {
				                notEmpty: {
				                    message: '*所属单位不能为空'
				                }
				            }
		            	},
		            	"sysUser.username": {
						    validators: validUsername
		                },
		                "sysUser.password": {
						    validators: validPassword
		                },
		                "password2": {
						    validators: validPassword2
		                },
		                "sysUser.name": {
						    validators: {
				                notEmpty: {
				                    message: '*用户姓名不能为空'
				                },
				                stringLength: {
				                    max: 15,
				                    message: '*确认密码长度必须小于15'
				                }
				            }
		                },
		                "sysUser.mobile": {
						    validators: {
						    	regexp: {
									regexp: /^1(3|4|5|7|8)\d{9}$/,
									message: '*移动电话格式不对'
								}
				            }
		                },
		                "sysUser.email": {
						    validators: {
						    	regexp: {
									regexp: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/ ,
									message: '*邮箱格式不对'
								},
								stringLength: {
				                    max: 100,
				                    message: '*您的邮箱地址也太长了吧'
				                }
				            }
		                },
		                "sysUser.idcard": {
						    validators: {
						    	regexp: {
									regexp: /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/ ,
									message: '*身份证号格式不对'
								},
						    	notEmpty: {
				                    message: '*身份证号不能为空'
				                }
				            }
		                },
		                "sysUser.birth_date":{
		                	validators: {
				                notEmpty: {
				                    message: '*出生日期不能为空'
				                }
				            }
		                },
		                "sysUser.in_company_date":{
		                	validators: {
				                notEmpty: {
				                    message: '*入司时间不能为空'
				                }
				            }
		                }
		            }
		        }).on("success.form.bv", function (e) {
		            save();
		            return false;//阻止表单跳转
		        });
		});
	</script>